<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<!-- 筛选反馈类型 -->
			<cl-filter label="反馈类型">
				<cl-select prop="feedbackType" :options="options.feedbackType" />
			</cl-filter>
			<!-- 筛选处理状态 -->
			<cl-filter label="处理状态">
				<cl-select prop="processStatus" :options="options.processStatus" />
			</cl-filter>
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key placeholder="搜索反馈内容、联系方式" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="userfeedback-info" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { reactive } from "vue";

const { service } = useCool();

// 选项
const options = reactive({
	feedbackType: [
		{ label: "建议", value: 0 },
		{ label: "投诉", value: 1 },
		{ label: "其他", value: 2 }
	],
	processStatus: [
		{ label: "未处理", value: 0 },
		{ label: "处理中", value: 1 },
		{ label: "已处理", value: 2 }
	]
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: "反馈内容",
			prop: "feedbackContent",
			component: { name: "el-input", props: { type: "textarea", rows: 4 } },
			required: true
		},
		{
			label: "反馈类型",
			prop: "feedbackType",
			component: { name: "el-radio-group", options: options.feedbackType },
			value: 0,
			required: true
		},
		{
			label: "反馈时间",
			prop: "feedbackTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" }
			},
			required: true
		},
		{
			label: "处理状态",
			prop: "processStatus",
			component: { name: "el-radio-group", options: options.processStatus },
			value: 0,
			required: true
		},
		{
			label: "处理人",
			prop: "processor",
			component: { name: "el-input", props: { clearable: true } }
		},
		{
			label: "处理时间",
			prop: "processTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" }
			}
		},
		{
			label: "联系方式",
			prop: "contactInfo",
			component: { name: "el-input", props: { clearable: true } },
			required: true
		},
		{
			label: "用户ID",
			prop: "userId",
			hook: "number",
			component: { name: "el-input-number" },
			required: true
		},
		// {
		// 	label: "反馈ID",
		// 	prop: "feedbackId",
		// 	hook: "number",
		// 	component: { name: "el-input-number" },
		// 	required: true
		// },
		{
			label: "备注",
			prop: "remark",
			component: { name: "el-input", props: { type: "textarea", rows: 4 } }
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{
			label: "反馈内容",
			prop: "feedbackContent",
			showOverflowTooltip: true,
			minWidth: 200
		},
		{ label: "反馈类型", prop: "feedbackType", dict: options.feedbackType, minWidth: 120 },
		{
			label: "反馈时间",
			prop: "feedbackTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "处理状态",
			prop: "processStatus",
			dict: options.processStatus,
			minWidth: 120
		},
		{ label: "处理人", prop: "processor", minWidth: 140 },
		{
			label: "处理时间",
			prop: "processTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{ label: "联系方式", prop: "contactInfo", minWidth: 140 },
		{ label: "用户ID", prop: "userId", minWidth: 140 },
		// { label: "反馈ID", prop: "feedbackId", minWidth: 140 },
		{ label: "备注", prop: "remark", showOverflowTooltip: true, minWidth: 200 },
		{
			label: "更新时间",
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "创建时间",
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" }
		},
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.userfeedback.info
	},
	(app) => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
